package com.fay.basic.proxy;

import java.util.Arrays;

public class SortInPlace {
    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 2, 2, 3, 4, 5, 6};
        int[] newArray = sort(nums);

        System.out.println(Arrays.toString(nums));

        //[1, 2, 3, 4, 5, 6, 5, 6]
        System.out.println(Arrays.toString(newArray));
        //[1, 2, 3, 4, 5, 6]

    }
    
    public static int[] sort(int[] nums) {
        if (nums==null || nums.length < 2) return new int[]{};
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[i] != nums[j]) {
                nums[++i] = nums[j];
            }
        }
        return Arrays.copyOf(nums, i + 1);
    }
}
